/**
 *    @file       httpservertask.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/21/2014 04:42:59 PM
 *
 *    @author     Theophilsu (), wangtf418@gmail.com
 */
#ifndef _SF_HTTPSERVERTASK_H_
#define _SF_HTTPSERVERTASK_H_
#include "servertask.h"

class httpservertask : public servertask
{
public:
	httpservertask(csocket *sock, netprocessthread *netthread, const comargs *args = NULL, bf_size_t headbuflen = HTTP_HEAD_LEN, bf_size_t bodybuflen = HTTP_BODY_LEN);
	virtual ~httpservertask();
	enum method_t
	{
		METHOD_UNKNOW =0,
		METHOD_HEAD = 1,
		METHOD_GET = 2,
		METHOD_POST = 3
	};

public:
	virtual bf_int_t init(bf_time_t timeout = SOCKTASK_TIMEOUT, bf_int_t sock_buflen = 102400);
	virtual bf_int_t proc_msg(message *msg);

protected:
	virtual bf_int_t recv_process();
	virtual bf_int_t read_head();
	virtual bf_int_t read_body();
	virtual bf_int_t process_recv_packet(bf_char_t *buf, bf_size_t buflen);
	virtual void reset_buf();
	virtual bf_int_t process_packets();

protected:
	virtual bf_int_t process_head();
	virtual bf_int_t process_get();
	virtual bf_int_t process_post(bf_char_t *buf, bf_size_t buflen, bf_size_t offset, bf_size_t contentlen);
	virtual bf_int_t process_headline();

protected:
	bf_char_t *m_headbuf;
	bf_char_t *m_bodybuf;
	bf_size_t m_max_headlen;
	bf_size_t m_body_buflen;

protected:
	read_state_t m_read_state;
	bf_size_t m_cur_recvlen;
	bf_size_t m_content_len;
	bf_size_t m_has_recv_contentlen;

public:
	method_t m_method;
	std::string m_http_head;
	std::string m_http_ver;
	std::string m_http_path;
};

#endif

